package com.hzcx.app.simplechat.ui.moment.dialog;

import android.content.Context;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.hzcx.app.simplechat.R;
import com.hzcx.app.simplechat.base.BaseDialog;
import com.hzcx.app.simplechat.util.app.AppHelper;
import com.hzcx.app.simplechat.util.empty.EmptyUtils;

import butterknife.BindView;

/**
 * 评论弹窗
 */
public class MomentCommentDialog extends BaseDialog {
    @BindView(R.id.et_content)
    EditText etContent;
    @BindView(R.id.tv_commit)
    TextView tvCommit;

    private OnCommentListener listener;
    private String commentUserId;

    public MomentCommentDialog(@NonNull Context context,String commentUserId, OnCommentListener listener) {
        super(context);
        this.listener = listener;
        this.commentUserId=commentUserId;
    }

    @Override
    public int getLayout() {
        return R.layout.dialog_moment_comment;
    }

    @Override
    public void initPresenter() {

    }

    @Override
    public void initView() {
        // 显示在最底部
        getWindow().setGravity(Gravity.BOTTOM);
        getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);

        tvCommit.setOnClickListener(view -> {
            if (EmptyUtils.isEmpty(etContent.getText().toString())) {
                showError("请输入评论内容");
                return;
            }
            if (listener != null) {
                listener.comment(etContent.getText().toString(),commentUserId);
            }
            dismiss();
        });

        AppHelper.showSoftKeyboard(etContent,context);
    }

    @Override
    public void initData() {

    }

    public interface OnCommentListener {
        void comment(String comment,String commentUserId);
    }
}
